package com.leihao.marketing.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.leihao.common.core.domain.R;
import com.leihao.common.core.web.controller.BaseController;
import com.leihao.common.core.web.page.TableDataInfo;
import com.leihao.marketing.domain.Coupon;
import com.leihao.marketing.domain.CouponListRequest;
import com.leihao.marketing.domain.ListRequest;
import com.leihao.marketing.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("coupon")
public class CouponController extends BaseController {
    @Autowired
    private CouponService couponService;

    /**
     * 条件查询优惠券列表
     * @param couponListRequest
     * @return
     */
    @PostMapping("queryList")
    public R<IPage<Coupon>> queryList(@RequestBody CouponListRequest couponListRequest) {
        return R.ok(couponService.queryList(couponListRequest));
    }

    /**
     * 查询所有优惠券
     * @return
     */
    @GetMapping("findAll")
    public R<List<Coupon>> findAll(){
        return R.ok(couponService.findAll());
    }
    /**
     * 添加优惠券
     * @param coupon
     * @return
     */
    @PostMapping("add")
    public R add(@RequestBody Coupon coupon) {
        couponService.save(coupon);
        return R.ok();
    }


    /**
     * 修改优惠券
     * @param coupon
     * @return
     */
    @PutMapping("update")
    public R update(@RequestBody Coupon coupon) {
        couponService.updateById(coupon);
        return R.ok();
    }

    /**
     * 逻辑删除
     * @param couponId
     * @return
     */
    @DeleteMapping("delete/{couponId}")
    public R delete(@PathVariable Integer couponId){
        couponService.removeById(couponId);
        return R.ok("删除成功");
    }
}
